package com.gilight.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.model.SysWebsiteConfig;
import com.gilight.base.service.ISysWebsiteConfigService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author cyt
 * @since 2021-06-04
 */
@RestController
@RequestMapping("/web/sys-website-config")
public class SysWebsiteConfigController {

    @Autowired
    private ISysWebsiteConfigService sysWebsiteConfigServiceImpl;


    @ApiOperation(value = "根据id查询")
    @RequestMapping(value = "/selectById", method = {RequestMethod.GET})
    public ResultEntity selectById(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setData(sysWebsiteConfigServiceImpl.getById(sysWebsiteConfig.getId()));
        return resultEntity;
    }

    @ApiOperation(value = "条件查询")
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    public ResultEntity page(SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        QueryWrapper<SysWebsiteConfig> queryWrapper = new QueryWrapper<>(sysWebsiteConfig);
        resultEntity.setData(sysWebsiteConfigServiceImpl.list(queryWrapper));
        return resultEntity;
    }

    @ApiOperation(value = "分页条件查询")
    @RequestMapping(value = "/page", method = {RequestMethod.GET})
    public ResultEntity page(SysWebsiteConfig sysWebsiteConfig,
                             @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {
        ResultEntity resultEntity = new ResultEntity();
        QueryWrapper<SysWebsiteConfig> queryWrapper = new QueryWrapper<>(sysWebsiteConfig);
        Page page = new Page(pageNo,pageSize);
        resultEntity.setData(sysWebsiteConfigServiceImpl.page(page,queryWrapper));
        return resultEntity;
    }

    @ApiOperation(value = "添加")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public ResultEntity save(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        sysWebsiteConfigServiceImpl.save(sysWebsiteConfig);
        return resultEntity;
    }

    @ApiOperation(value = "批量添加")
    @RequestMapping(value = "/saveBatch", method = {RequestMethod.POST})
    public ResultEntity save(@RequestBody List<SysWebsiteConfig> list) {
        ResultEntity resultEntity = new ResultEntity();
        sysWebsiteConfigServiceImpl.saveBatch(list);
        return resultEntity;
    }

    @ApiOperation(value = "更新")
    @RequestMapping(value = "/updateById", method = {RequestMethod.POST})
    public ResultEntity updateById(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        sysWebsiteConfigServiceImpl.updateById(sysWebsiteConfig);
        return resultEntity;
    }

    @ApiOperation(value = "添加或更新")
    @RequestMapping(value = "/saveOrUpdate", method = {RequestMethod.POST})
    public ResultEntity saveOrUpdate(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        sysWebsiteConfigServiceImpl.saveOrUpdate(sysWebsiteConfig);
        return resultEntity;
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/removeById", method = {RequestMethod.POST})
    public ResultEntity removeById(@RequestBody SysWebsiteConfig sysWebsiteConfig) {
        ResultEntity resultEntity = new ResultEntity();
        sysWebsiteConfigServiceImpl.removeById(sysWebsiteConfig.getId());
        return resultEntity;
    }



}
